/**
 * Created by baiguiren on 1/16/17.
 */

let async = require('async');
let fs = require('fs');

async.auto({
  read_data: async.apply(fs.readFile, __dirname + '/data.txt', 'utf-8'),
  process_data:['read_data', (results, cb) => {
    //console.log(results.read_data);
    cb();
  }]
}, (err, results) => {
  //console.log(err ? err : results);
});

async.auto({
  get_data: (callback) => {
    console.log('in get_data');
    callback(null, 'data', 'converted to array');
  },
  make_folder: (callback) => {
    console.log('in make_folder');
    callback(null, 'folder');
  },
  write_file: (()=>['get_data', 'make_folder', (results, callback) => {
    console.log('in write_file', JSON.stringify(results));
    callback(null, 'filename');
  }])(),
  email_link: ['write_file', (results, callback) => {
    console.log('in email_link', JSON.stringify(results));
    callback(null, {file: results.write_file, email: 'awk@gmail.com'});
  }]
}, (err, results) => {
  //console.log(err ? err : results);
  console.log(err);
  console.log(results);
});

//console.log((()=>[1,2,3])());